<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include::header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <form class="form-horizontal m-t" id="editForm">
            <input th:value="${order.id}" type="hidden" name="id" value="0" id="id"/>
            <div class="ibox-content">
                <!-- 第一行 -->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">客户名称：</label>
                            <div class="col-sm-7">
                                <input th:value="${order.customer_name}" id="customer_name" name="customer_name"
                                       class="form-control"
                                       type="text" required="true">
                            </div>
                            <span class="col-sm-1 control-label" style="color: red;">*</span>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">收货人：</label>
                            <div class="col-sm-7">
                                <input th:value="${order.consignee}" id="consignee" name="consignee"
                                       class="form-control"
                                       type="text" required="true">
                            </div>
                            <span class="col-sm-1 control-label" style="color: red;">*</span>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">收货电话：</label>
                            <div class="col-sm-7">
                                <input th:value="${order.consignee_phone}" id="consignee_phone" name="consignee_phone"
                                       class="form-control"
                                       type="text" required="true">
                            </div>
                            <span class="col-sm-1 control-label" style="color: red;">*</span>
                        </div>
                    </div>

                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">收货地址：</label>
                            <div class="col-sm-7">
                                <input th:value="${order.consignee_address}" id="consignee_address"
                                       name="consignee_address" class="form-control"
                                       type="text" required="true">
                            </div>
                            <span class="col-sm-1 control-label" style="color: red;">*</span>
                        </div>
                    </div>

                </div>
            </div>
        </form>
    </div>
    <button type="button" class="btn btn-primary col-sm-2 col-sm-offset-5" id="btnSave">保存</button>

</div>
<div th:include="include::footer"></div>
</body>
<script>
    $(document).ready(function () {
        $('#btnSave').on('click', function () {
            var consignee = $('#consignee').val();
            var customer_name = $('#customer_name').val();
            var consignee_phone = $('#consignee_phone').val();
            var consignee_address = $('#consignee_address').val();
            $.ajax({
                type: 'POST',
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                url: '/lgs/order/update2',
                data: JSON.stringify({id: $('#id').val(), customer_name: customer_name, consignee: consignee, consignee_phone: consignee_phone, consignee_address: consignee_address
        }),
            success : function (result) {
                debugger;
                if (result.code == 0) {
                    parent.layer.msg("操作成功");
                    var orderRow = $.parseJSON(sessionStorage.getItem("orderRow"));
                    orderRow.customer_name = customer_name;
                    orderRow.consignee = consignee;
                    orderRow.consignee_phone = consignee_phone;
                    orderRow.consignee_address = consignee_address;
                    sessionStorage.setItem("orderRow", JSON.stringify(orderRow));

                    parent.reLoad();
                    layer.closeAll();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    parent.layer.msg(result.msg);
                }
            }
            ,
            error: function () {
            }
        })
            ;
        });
    });
</script>
</html>
